package com.sky.service.impl;

import com.sky.entity.Orders;
import com.sky.mapper.ReportMapper;
import com.sky.service.ReportService;
import com.sky.vo.TurnoverReportVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
public class ReportServiceImpl implements ReportService {
    @Autowired
    ReportMapper reportMapper;
    @Override
    public TurnoverReportVO turnoverStatistics(String begin, String end) {
        TurnoverReportVO turnoverReportVO = new TurnoverReportVO();
        LocalDateTime beginVO = LocalDateTime.parse(begin+" 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        LocalDateTime endVO = LocalDateTime.parse(end + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        List<Orders> list = reportMapper.turnoverStatistics(beginVO,endVO);
        String timeVO="";
        LocalDate time = beginVO.toLocalDate();
        while(time.isBefore(endVO.toLocalDate().plusDays(1L))){
            timeVO=timeVO+time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))+",";
            time = time.plusDays(1);
        }
        timeVO = timeVO.substring(0,timeVO.length()-1);
        turnoverReportVO.setDateList(timeVO);
        turnoverReportVO.setTurnoverList("406.0,1520.0,75.0");
        return turnoverReportVO;
    }
}
